import { ref } from 'vue'
import { ConsultType } from '@/enums/index'
import type { ConsultIllness, PartialConsult } from '@/types/consult'
import { defineStore } from 'pinia'

export const useConsultStore = defineStore(
  'consult',
  () => {
    const consult = ref<PartialConsult>({})

    const setType = (type: ConsultType) => {
      consult.value.type = type
    }
    const setIllnessType = (type: 0 | 1) => {
      consult.value.illnessType = type
    }
    const setDepId = (id: string) => {
      consult.value.depId = id
    }

    const setIllness = (illness: ConsultIllness) => {
      consult.value.illnessDesc = illness.illnessDesc
      consult.value.illnessTime = illness.illnessTime
      consult.value.consultFlag = illness.consultFlag
      consult.value.pictures = illness.pictures
    }
    const setPatient = (id: string) => {
      consult.value.patientId = id
    }
    const setCunpon = (id?: string) => {
      consult.value.couponId = id
    }

    const clear = () => {
      consult.value = {}
    }
    return { consult, setType, setIllnessType, setDepId, setIllness, setPatient, setCunpon, clear }
  },
  {
    persist: true,
  },
)
